<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/Language.php'; //include thu vien language
require_once 'CMS/User.php';
//Người tạo : Bùi Thành Nguyên - Team 2
//Module 	: Edit category module
//Chức năng	: Hiển thị form add category cha

class Category_AddLCategoryController extends BaseUserController{

	public function init(){
		parent::init();
		$this->_helper->layout->disableLayout();
		$user = new User();
		$user->init();
		$user->check_login();
		
	}
	
	//Chức năng show form cho người dùng
	public function indexAction(){
	
			/*========== Start Load Language ==========*/
			$language = new Language(APPLICATION_PATH . '/widgets/category/');
			if(isset($_SESSION['language']))
			{
				$language_id = $_SESSION['language'];
				$tbLanguage = new Language_Model_Language();
				$name = $tbLanguage->getNameLanguage($language_id);
				$language->load($name['name']);
			}
			else
				$language->load('Default');		
			/*========== End Load Language ==========*/
				
			/*========== Start Get Text ==============*/
			$this->view->textName 		= $language->get('text_categoryleafname');
			$this->view->textSave 		= $language->get('text_save');
			$this->view->textError2 	= $language->get('error2');
			$this->view->textError3 	= $language->get('error3');
			$this->view->textError9 	= $language->get('error9');
			$this->view->textError10 	= $language->get('error10');
			$this->view->textError11 	= $language->get('error11');
			$this->view->textError12 	= $language->get('error12');
			$this->view->textError14 	= $language->get('error14');
			/*========== End Text ==============*/
		/*=========== Get all languages =============*/
			$all_languages = $tbLanguage->getAllLanguages();
			$languages = array();
			foreach ($all_languages as $lang){
				$languages[] = array(
									'id' 	=> $lang['language_id'],
									'name'	=> $lang['name']
									);
			}
			$this->view->languages = $languages;
		/*=========== End get ==================*/	
		$path = APPLICATION_PATH."/widgets/category/";
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		$user = new User();
			$user->init();
			$user->check_login();
			$hasmodify = $user->modifiy_widget($xmlconfig->name);
		if($hasmodify=="true")
		{
		}
		else 
		{
			$this->view->error = 2 ;
		}
		//lấy type của category cần add
		
		if(count($_GET) && isset($_GET["catetype"]) && isset($_GET["parent"])) //kiểm tra category type
		{
			$category_type="-1";
			if($_GET["catetype"]=="index")
				$category_type=1;
			else if($_GET["catetype"]=="news")
				$category_type=2;
			else if($_GET["catetype"]=="qa")
				$category_type=3;
			$this->view->type=$category_type;
			$this->view->parent_id=$_GET["parent"];
		}
		else
		{
			$this->view->type="-1";
		}
	}
	
}